package com.hengpeng.msls.service.client.shortcut;

import com.hengpeng.itfinbase.persist.MemberShare.UserType;

/**
 * 快捷登陆serviceFactory
 * @author wuhaifei
 * @version 1.0 2012-12-28
 */
public class ShortcutServiceFactory
{
	private static final String PREFIX = "com.hengpeng.msls.service.client.shortcut";

	private static final String SUFFIX = "ServiceImpl";

	/**
	 * 根据快捷登陆用户类型获取对应处理类
	 * @param type 用户类型
	 * @return
	 */
	public static ShortcutBaseService getService(UserType type)
	{
		if (type == null)
		{
			return null;
		}
		StringBuffer className = new StringBuffer(PREFIX);
		className.append(".");
		// 用户类型转小写
		String typeLower = type.name().toLowerCase();
		className.append(typeLower);
		className.append(".");
		// 首字母大写
		className.append(typeLower.substring(0, 1).toUpperCase());
		className.append(typeLower.substring(1, typeLower.length()));
		className.append(SUFFIX);
		try
		{
			Class<?> clazz = ShortcutServiceFactory.class.getClassLoader().loadClass(className.toString());
			return (ShortcutBaseService) clazz.newInstance();
		}
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (InstantiationException e)
		{
			e.printStackTrace();
		}
		catch (IllegalAccessException e)
		{
			e.printStackTrace();
		}

		return null;
	}
}
